`
https://leetcode.cn/problems/find-k-closest-elements/
`

/**
 * @param {number[]} arr
 * @param {number} k
 * @param {number} x
 * @return {number[]}
 */
var findClosestElements = function (arr, k, x) {
  let left = 0, right = arr.length - 1
  while (right - left + 1 > k) {
    // 判断左右两边哪个离 x 更远，删掉
    if (Math.abs(arr[left] - x) > Math.abs(arr[right] - x)) {
      left++
    } else {
      right--
    }
  }
  return arr.slice(left, right + 1)
};